package com.tox.dao.impl;

import java.util.ArrayList;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.tox.dao.JavatoxUserDAO;
import com.tox.dao.pojo.JavatoxUser;
import com.tox.util.MD5;

public class JavatoxUserDaoImpl extends HibernateDaoSupport implements JavatoxUserDAO {

	@Override
	public Boolean login(String username, String password) {
		
		
		List<JavatoxUser> list=(ArrayList<JavatoxUser>)super.getHibernateTemplate().find("select user from JavatoxUser user where user.username=? and user.password=?",new String[]{username,MD5.generatePassword(password)});
		

		System.out.println(list.size());
		if(list.size()!=0){
			ServletActionContext.getRequest().getSession().setAttribute("user", list.get(0));
			return true;
		}
		return false;
	
	}

	@Override
	public Boolean register(String username, String password,String nickname) {
		
		JavatoxUser javatoxUser=new JavatoxUser();
		javatoxUser.setUsername(username);
		javatoxUser.setMobile("187681225858");
		javatoxUser.setNickname(nickname);
		javatoxUser.setPassword(MD5.generatePassword(password));
		javatoxUser.setEmail("d20041990@163.com");
		javatoxUser.setLastLoginTime("2121");
		javatoxUser.setRegTime((System.currentTimeMillis()+"").substring(0, 10));
		super.getHibernateTemplate().save(javatoxUser);
		return true;
	}

	

}
